home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / drivers / raiden.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  21KB  |  624 lines

  1. /***************************************************************************
  2.  
  3.     Raiden                            (c) 1990 Seibu Kaihatsu
  4.     Raiden (Alternate Hardware)        (c) 1990 Seibu Kaihatsu
  5.     Raiden (Korean license)            (c) 1990 Seibu Kaihatsu
  6.  
  7.     driver by Oliver Bergmann, Bryan McPhail, Randy Mongenel
  8.  
  9.  
  10.     The alternate hardware version is probably earlier than the main set.
  11.     It looks closer to Dynamite Duke (1989 game), while the main set looks
  12.     closer to the newer 68000 games in terms of graphics registers used, etc.
  13.  
  14.     As well as different graphics registers the alternate set has a
  15.     different memory map, and different fix char layer memory layout!
  16.  
  17.     To access test mode, reset with both start buttons held.
  18.  
  19.     Coins are controlled by the sound cpu, there is a small kludge to allow
  20.     the game to coin up if sound is off.
  21.  
  22.     The country byte is stored at 0xffffd in the main cpu region,
  23.     (that's 0x1fffe in program rom 4).
  24.  
  25.         0x80  = World/Japan version? (Seibu Kaihatsu)
  26.         0x81  = USA version (Fabtek license)
  27.         0x82  = Taiwan version (Liang HWA Electronics license)
  28.         0x83  = Hong Kong version (Wah Yan Electronics license)
  29.         0x84  = Korean version (IBL Corporation license)
  30.  
  31.         There are also strings for Spanish, Greece, Mexico, Middle &
  32.         South America though it's not clear if they are used.
  33.  
  34.     Todo: add support for Coin Mode B
  35.  
  36.     One of the boards is SEI8904 with SEI9008 subboard.
  37.  
  38. ***************************************************************************/
  39.  
  40. #include "driver.h"
  41. #include "vidhrdw/generic.h"
  42. #include "cpu/z80/z80.h"
  43. #include "sndhrdw/seibu.h"
  44.  
  45. READ_HANDLER( raiden_background_r );
  46. READ_HANDLER( raiden_foreground_r );
  47. WRITE_HANDLER( raiden_background_w );
  48. WRITE_HANDLER( raiden_foreground_w );
  49. WRITE_HANDLER( raiden_text_w );
  50. WRITE_HANDLER( raidena_text_w );
  51. int raiden_vh_start(void);
  52. WRITE_HANDLER( raiden_control_w );
  53. void raiden_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh);
  54.  
  55. static unsigned char *raiden_shared_ram;
  56. extern unsigned char *raiden_back_data,*raiden_fore_data,*raiden_scroll_ram;
  57.  
  58. /***************************************************************************/
  59.  
  60. static READ_HANDLER( raiden_shared_r ) { return raiden_shared_ram[offset]; }
  61. static WRITE_HANDLER( raiden_shared_w ) { raiden_shared_ram[offset]=data; }
  62.  
  63. static READ_HANDLER( raiden_sound_r )
  64. {
  65.     static int latch=0;
  66.     int erg,orig,coin=readinputport(4);
  67.     orig=seibu_shared_sound_ram[offset];
  68.  
  69.     /* Small kludge to allows coins with sound off */
  70.     if (coin==0) latch=0;
  71.     if (offset==4 && (!Machine->sample_rate) && coin && latch==0) {
  72.         latch=1;
  73.         return coin;
  74.      }
  75.  
  76.     switch (offset)
  77.     {/* misusing $d006 as a latch...but it works !*/
  78.         case 0x04:{erg=seibu_shared_sound_ram[6];seibu_shared_sound_ram[6]=0;break;} /* just 1 time */
  79.         case 0x06:{erg=0xa0;break;}
  80.         case 0x0a:{erg=0;break;}
  81.         default: erg=seibu_shared_sound_ram[offset];
  82.     }
  83.     return erg;
  84. }
  85.  
  86. /******************************************************************************/
  87.  
  88. static struct MemoryReadAddress readmem[] =
  89. {
  90.     { 0x00000, 0x07fff, MRA_RAM },
  91.     { 0x0a000, 0x0afff, raiden_shared_r },
  92.     { 0x0b000, 0x0b000, input_port_0_r },
  93.     { 0x0b001, 0x0b001, input_port_1_r },
  94.     { 0x0b002, 0x0b002, input_port_2_r },
  95.     { 0x0b003, 0x0b003, input_port_3_r },
  96.     { 0x0d000, 0x0d00f, raiden_sound_r },
  97.     { 0xa0000, 0xfffff, MRA_ROM },
  98.     { -1 }    /* end of table */
  99. };
  100.  
  101. static struct MemoryWriteAddress writemem[] =
  102. {
  103.     { 0x00000, 0x06fff, MWA_RAM },
  104.     { 0x07000, 0x07fff, MWA_RAM, &spriteram, &spriteram_size },
  105.     { 0x0a000, 0x0afff, raiden_shared_w, &raiden_shared_ram },
  106.     { 0x0b000, 0x0b007, raiden_control_w },
  107.     { 0x0c000, 0x0c7ff, raiden_text_w, &videoram },
  108.     { 0x0d000, 0x0d00f, seibu_soundlatch_w, &seibu_shared_sound_ram },
  109.     { 0x0d060, 0x0d067, MWA_RAM, &raiden_scroll_ram },
  110.     { 0xa0000, 0xfffff, MWA_ROM },
  111.     { -1 }    /* end of table */
  112. };
  113.  
  114. static struct MemoryReadAddress sub_readmem[] =
  115. {
  116.     { 0x00000, 0x01fff, MRA_RAM },
  117.     { 0x02000, 0x027ff, raiden_background_r },
  118.     { 0x02800, 0x02fff, raiden_foreground_r },
  119.     { 0x03000, 0x03fff, paletteram_r },
  120.     { 0x04000, 0x04fff, raiden_shared_r },
  121.     { 0xc0000, 0xfffff, MRA_ROM },
  122.     { -1 }    /* end of table */
  123. };
  124.  
  125. static struct MemoryWriteAddress sub_writemem[] =
  126. {
  127.     { 0x00000, 0x01fff, MWA_RAM },
  128.     { 0x02000, 0x027ff, raiden_background_w, &raiden_back_data },
  129.     { 0x02800, 0x02fff, raiden_foreground_w, &raiden_fore_data },
  130.     { 0x03000, 0x03fff, paletteram_xxxxBBBBGGGGRRRR_w, &paletteram },
  131.     { 0x04000, 0x04fff, raiden_shared_w },
  132.     { 0x07ffe, 0x0afff, MWA_NOP },
  133.     { 0xc0000, 0xfffff, MWA_ROM },
  134.     { -1 }    /* end of table */
  135. };
  136.  
  137. /************************* Alternate board set ************************/
  138.  
  139. static struct MemoryReadAddress alt_readmem[] =
  140. {
  141.     { 0x00000, 0x07fff, MRA_RAM },
  142.     { 0x08000, 0x08fff, raiden_shared_r },
  143.     { 0x0a000, 0x0a00f, raiden_sound_r },
  144.     { 0x0e000, 0x0e000, input_port_0_r },
  145.     { 0x0e001, 0x0e001, input_port_1_r },
  146.     { 0x0e002, 0x0e002, input_port_2_r },
  147.     { 0x0e003, 0x0e003, input_port_3_r },
  148.     { 0xa0000, 0xfffff, MRA_ROM },
  149.     { -1 }    /* end of table */
  150. };
  151.  
  152. static struct MemoryWriteAddress alt_writemem[] =
  153. {
  154.     { 0x00000, 0x06fff, MWA_RAM },
  155.     { 0x07000, 0x07fff, MWA_RAM, &spriteram, &spriteram_size },
  156.     { 0x08000, 0x08fff, raiden_shared_w, &raiden_shared_ram },
  157.     { 0x0a000, 0x0a00f, seibu_soundlatch_w, &seibu_shared_sound_ram },
  158.     { 0x0b000, 0x0b007, raiden_control_w },
  159.     { 0x0c000, 0x0c7ff, raidena_text_w, &videoram },
  160.     { 0x0f000, 0x0f035, MWA_RAM, &raiden_scroll_ram },
  161.     { 0xa0000, 0xfffff, MWA_ROM },
  162.     { -1 }    /* end of table */
  163. };
  164.  
  165. /******************************************************************************/
  166.  
  167. SEIBU_SOUND_SYSTEM_YM3812_MEMORY_MAP(input_port_4_r); /* Coin port */
  168.  
  169. /******************************************************************************/
  170.  
  171. INPUT_PORTS_START( raiden )
  172.     PORT_START    /* IN0 */
  173.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP    | IPF_8WAY | IPF_PLAYER1 )
  174.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN  | IPF_8WAY | IPF_PLAYER1 )
  175.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT  | IPF_8WAY | IPF_PLAYER1 )
  176.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_8WAY | IPF_PLAYER1 )
  177.     PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 | IPF_PLAYER1 )
  178.     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 | IPF_PLAYER1 )
  179.     PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNUSED )
  180.     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_START1 )
  181.  
  182.     PORT_START    /* IN1 */
  183.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP    | IPF_8WAY | IPF_PLAYER2 )
  184.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN  | IPF_8WAY | IPF_PLAYER2 )
  185.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT  | IPF_8WAY | IPF_PLAYER2 )
  186.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_8WAY | IPF_PLAYER2 )
  187.     PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 | IPF_PLAYER2 )
  188.     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 | IPF_PLAYER2 )
  189.     PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNUSED )
  190.     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_START2 )
  191.  
  192.     PORT_START    /* Dip switch A */
  193.     PORT_DIPNAME( 0x01, 0x01, "Coin Mode" )
  194.     PORT_DIPSETTING(    0x01, "A" )
  195.     PORT_DIPSETTING(    0x00, "B" )
  196.     /* Coin Mode A */
  197.     PORT_DIPNAME( 0x1e, 0x1e, DEF_STR( Coinage ) )
  198.     PORT_DIPSETTING(    0x14, DEF_STR( 6C_1C ) )
  199.     PORT_DIPSETTING(    0x16, DEF_STR( 5C_1C ) )
  200.     PORT_DIPSETTING(    0x18, DEF_STR( 4C_1C ) )
  201.     PORT_DIPSETTING(    0x1a, DEF_STR( 3C_1C ) )
  202.     PORT_DIPSETTING(    0x02, DEF_STR( 8C_3C ) )
  203.     PORT_DIPSETTING(    0x1c, DEF_STR( 2C_1C ) )
  204.     PORT_DIPSETTING(    0x04, DEF_STR( 5C_3C ) )
  205.     PORT_DIPSETTING(    0x06, DEF_STR( 3C_2C ) )
  206.     PORT_DIPSETTING(    0x1e, DEF_STR( 1C_1C ) )
  207.     PORT_DIPSETTING(    0x08, DEF_STR( 2C_3C ) )
  208.     PORT_DIPSETTING(    0x12, DEF_STR( 1C_2C ) )
  209.     PORT_DIPSETTING(    0x10, DEF_STR( 1C_3C ) )
  210.     PORT_DIPSETTING(    0x0e, DEF_STR( 1C_4C ) )
  211.     PORT_DIPSETTING(    0x0c, DEF_STR( 1C_5C ) )
  212.     PORT_DIPSETTING(    0x0a, DEF_STR( 1C_6C ) )
  213.     PORT_DIPSETTING(    0x00, DEF_STR( Free_Play ) )
  214.  
  215.     /* Coin Mode B */
  216. /*    PORT_DIPNAME( 0x06, 0x06, DEF_STR( Coin_A ) )
  217.     PORT_DIPSETTING(    0x00, "5C/1C or Free if Coin B too" )
  218.     PORT_DIPSETTING(    0x02, DEF_STR( 3C_1C ) )
  219.     PORT_DIPSETTING(    0x04, DEF_STR( 2C_1C ) )
  220.     PORT_DIPSETTING(    0x06, DEF_STR( 1C_1C ) )
  221.     PORT_DIPNAME( 0x18, 0x18, DEF_STR( Coin_B ) )
  222.     PORT_DIPSETTING(    0x18, DEF_STR( 1C_2C ) )
  223.     PORT_DIPSETTING(    0x10, DEF_STR( 1C_3C ) )
  224.     PORT_DIPSETTING(    0x08, DEF_STR( 1C_5C ) )
  225.     PORT_DIPSETTING(    0x00, "1C/6C or Free if Coin A too" ) */
  226.  
  227.     PORT_DIPNAME( 0x20, 0x20, "Credits to Start" )
  228.     PORT_DIPSETTING(    0x20, "1" )
  229.     PORT_DIPSETTING(    0x00, "2" )
  230.     PORT_DIPNAME( 0x40, 0x40, DEF_STR( Unused ) )
  231.     PORT_DIPSETTING(    0x40, DEF_STR( Off ) )
  232.     PORT_DIPSETTING(    0x00, DEF_STR( On ) )
  233.     PORT_DIPNAME( 0x80, 0x80, DEF_STR( Flip_Screen ) )
  234.     PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
  235.     PORT_DIPSETTING(    0x00, DEF_STR( On ) )
  236.  
  237.     PORT_START    /* Dip switch B */
  238.     PORT_DIPNAME( 0x03, 0x03, DEF_STR( Lives ) )
  239.     PORT_DIPSETTING(    0x02, "1" )
  240.     PORT_DIPSETTING(    0x01, "2" )
  241.     PORT_DIPSETTING(    0x03, "3" )
  242.     PORT_DIPSETTING(    0x00, "5" )
  243.     PORT_DIPNAME( 0x0c, 0x0c, DEF_STR( Bonus_Life ) )
  244.     PORT_DIPSETTING(    0x08, "80000 300000" )
  245.     PORT_DIPSETTING(    0x0c, "150000 400000" )
  246.     PORT_DIPSETTING(    0x04, "300000 1000000" )
  247.     PORT_DIPSETTING(    0x00, "1000000 5000000" )
  248.     PORT_DIPNAME( 0x30, 0x30, DEF_STR( Difficulty ) )
  249.     PORT_DIPSETTING(    0x20, "Easy" )
  250.     PORT_DIPSETTING(    0x30, "Normal" )
  251.     PORT_DIPSETTING(    0x10, "Hard" )
  252.     PORT_DIPSETTING(    0x00, "Very Hard" )
  253.     PORT_DIPNAME( 0x40, 0x40, "Allow Continue" )
  254.     PORT_DIPSETTING(    0x00, DEF_STR( No ) )
  255.     PORT_DIPSETTING(    0x40, DEF_STR( Yes ) )
  256.     PORT_DIPNAME( 0x80, 0x80, DEF_STR( Demo_Sounds ) )
  257.     PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
  258.     PORT_DIPSETTING(    0x80, DEF_STR( On ) )
  259.  
  260.     PORT_START    /* Coins */
  261.     PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_COIN1 )
  262.     PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_COIN2 )
  263. INPUT_PORTS_END
  264.  
  265. /******************************************************************************/
  266.  
  267. static struct GfxLayout raiden_charlayout =
  268. {
  269.     8,8,        /* 8*8 characters */
  270.     2048,        /* 512 characters */
  271.     4,            /* 4 bits per pixel */
  272.     { 4,0,(0x08000*8)+4,0x08000*8  },
  273.     { 0,1,2,3,8,9,10,11 },
  274.     { 0*16, 1*16, 2*16, 3*16, 4*16, 5*16, 6*16, 7*16 },
  275.     128
  276. };
  277.  
  278. static struct GfxLayout raiden_spritelayout =
  279. {
  280.   16,16,    /* 16*16 tiles */
  281.   4096,        /* 2048*4 tiles */
  282.   4,        /* 4 bits per pixel */
  283.   { 12, 8, 4, 0 },
  284.   {
  285.     0,1,2,3, 16,17,18,19,
  286.     512+0,512+1,512+2,512+3,
  287.     512+8+8,512+9+8,512+10+8,512+11+8,
  288.   },
  289.   {
  290.     0*32, 1*32, 2*32, 3*32, 4*32, 5*32, 6*32, 7*32,
  291.     8*32, 9*32, 10*32, 11*32, 12*32, 13*32, 14*32, 15*32,
  292.   },
  293.   1024
  294. };
  295.  
  296. static struct GfxDecodeInfo raiden_gfxdecodeinfo[] =
  297. {
  298.     { REGION_GFX1, 0, &raiden_charlayout,   768, 16 },
  299.     { REGION_GFX2, 0, &raiden_spritelayout,   0, 16 },
  300.     { REGION_GFX3, 0, &raiden_spritelayout, 256, 16 },
  301.     { REGION_GFX4, 0, &raiden_spritelayout, 512, 16 },
  302.     { -1 } /* end of array */
  303. };
  304.  
  305. /******************************************************************************/
  306.  
  307. /* Parameters: YM3812 frequency, Oki frequency, Oki memory region */
  308. SEIBU_SOUND_SYSTEM_YM3812_HARDWARE(14318180/4,8000,REGION_SOUND1);
  309.  
  310. static int raiden_interrupt(void)
  311. {
  312.     return 0xc8/4;    /* VBL */
  313. }
  314.  
  315. static void raiden_eof_callback(void)
  316. {
  317.     buffer_spriteram_w(0,0); /* Could be a memory location instead */
  318. }
  319.  
  320. static struct MachineDriver machine_driver_raiden =
  321. {
  322.     /* basic machine hardware */
  323.     {
  324.         {
  325.             CPU_V30, /* NEC V30 CPU */
  326.             19000000, /* 20MHz is correct, but glitched!? */
  327.             readmem,writemem,0,0,
  328.             raiden_interrupt,1
  329.         },
  330.         {
  331.             CPU_V30, /* NEC V30 CPU */
  332.             19000000, /* 20MHz is correct, but glitched!? */
  333.             sub_readmem,sub_writemem,0,0,
  334.             raiden_interrupt,1
  335.         },
  336.         {
  337.             SEIBU_SOUND_SYSTEM_CPU(14318180/4)
  338.         }
  339.     },
  340.     60, DEFAULT_REAL_60HZ_VBLANK_DURATION*2,    /* frames per second, vblank duration */
  341.     70,    /* CPU interleave  */
  342.     seibu_sound_init_2,
  343.  
  344.     /* video hardware */
  345.     32*8, 32*8, { 0*8, 32*8-1, 2*8, 30*8-1 },
  346.     raiden_gfxdecodeinfo,
  347.     2048, 2048,
  348.     0,
  349.  
  350.     VIDEO_TYPE_RASTER | VIDEO_MODIFIES_PALETTE | VIDEO_BUFFERS_SPRITERAM,
  351.     raiden_eof_callback,
  352.     raiden_vh_start,
  353.     0,
  354.     raiden_vh_screenrefresh,
  355.  
  356.     /* sound hardware */
  357.     0,0,0,0,
  358.     {
  359.         SEIBU_SOUND_SYSTEM_YM3812_INTERFACE
  360.     }
  361. };
  362.  
  363. static struct MachineDriver machine_driver_raidena =
  364. {
  365.     /* basic machine hardware */
  366.     {
  367.         {
  368.             CPU_V30, /* NEC V30 CPU */
  369.             19000000, /* 20MHz is correct, but glitched!? */
  370.             alt_readmem,alt_writemem,0,0,
  371.             raiden_interrupt,1
  372.         },
  373.         {
  374.             CPU_V30, /* NEC V30 CPU */
  375.             19000000, /* 20MHz is correct, but glitched!? */
  376.             sub_readmem,sub_writemem,0,0,
  377.             raiden_interrupt,1
  378.         },
  379.         {
  380.             SEIBU_SOUND_SYSTEM_CPU(14318180/4)
  381.         }
  382.     },
  383.     60, DEFAULT_REAL_60HZ_VBLANK_DURATION*2,    /* frames per second, vblank duration */
  384.     60,    /* CPU interleave  */
  385.     seibu_sound_init_2,
  386.  
  387.     /* video hardware */
  388.     32*8, 32*8, { 0*8, 32*8-1, 2*8, 30*8-1 },
  389.     raiden_gfxdecodeinfo,
  390.     2048, 2048,
  391.     0,
  392.  
  393.     VIDEO_TYPE_RASTER | VIDEO_MODIFIES_PALETTE | VIDEO_BUFFERS_SPRITERAM,
  394.     raiden_eof_callback,
  395.     raiden_vh_start,
  396.     0,
  397.     raiden_vh_screenrefresh,
  398.  
  399.     /* sound hardware */
  400.     0,0,0,0,
  401.     {
  402.         SEIBU_SOUND_SYSTEM_YM3812_INTERFACE
  403.     }
  404. };
  405.  
  406. /***************************************************************************/
  407.  
  408. ROM_START( raiden )
  409.     ROM_REGION( 0x100000, REGION_CPU1 ) /* v30 main cpu */
  410.     ROM_LOAD_V20_ODD ( "rai1.bin",   0x0a0000, 0x10000, 0xa4b12785 )
  411.     ROM_LOAD_V20_EVEN( "rai2.bin",   0x0a0000, 0x10000, 0x17640bd5 )
  412.     ROM_LOAD_V20_ODD ( "rai3.bin",   0x0c0000, 0x20000, 0x9d735bf5 )
  413.     ROM_LOAD_V20_EVEN( "rai4.bin",   0x0c0000, 0x20000, 0x8d184b99 )
  414.  
  415.     ROM_REGION( 0x100000, REGION_CPU2 ) /* v30 sub cpu */
  416.     ROM_LOAD_V20_ODD ( "rai5.bin",   0x0c0000, 0x20000, 0x7aca6d61 )
  417.     ROM_LOAD_V20_EVEN( "rai6a.bin",  0x0c0000, 0x20000, 0xe3d35cc2 )
  418.  
  419.     ROM_REGION( 0x18000, REGION_CPU3 ) /* 64k code for sound Z80 */
  420.     ROM_LOAD( "rai6.bin", 0x000000, 0x08000, 0x723a483b )
  421.     ROM_CONTINUE(         0x010000, 0x08000 )
  422.  
  423.     ROM_REGION( 0x010000, REGION_GFX1 | REGIONFLAG_DISPOSE )
  424.     ROM_LOAD( "rai9.bin",     0x00000, 0x08000, 0x1922b25e ) /* chars */
  425.     ROM_LOAD( "rai10.bin",    0x08000, 0x08000, 0x5f90786a )
  426.  
  427.     ROM_REGION( 0x080000, REGION_GFX2 | REGIONFLAG_DISPOSE )
  428.     ROM_LOAD( "raiu0919.bin", 0x00000, 0x80000, 0xda151f0b ) /* tiles */
  429.  
  430.     ROM_REGION( 0x080000, REGION_GFX3 | REGIONFLAG_DISPOSE )
  431.     ROM_LOAD( "raiu0920.bin", 0x00000, 0x80000, 0xac1f57ac ) /* tiles */
  432.  
  433.     ROM_REGION( 0x090000, REGION_GFX4 | REGIONFLAG_DISPOSE )
  434.     ROM_LOAD( "raiu165.bin",  0x00000, 0x80000, 0x946d7bde ) /* sprites */
  435.  
  436.     ROM_REGION( 0x10000, REGION_SOUND1 )     /* ADPCM samples */
  437.     ROM_LOAD( "rai7.bin", 0x00000, 0x10000, 0x8f927822 )
  438. ROM_END
  439.  
  440. ROM_START( raidena )
  441.     ROM_REGION( 0x100000, REGION_CPU1 ) /* v30 main cpu */
  442.     ROM_LOAD_V20_ODD ( "rai1.bin",     0x0a0000, 0x10000, 0xa4b12785 )
  443.     ROM_LOAD_V20_EVEN( "rai2.bin",     0x0a0000, 0x10000, 0x17640bd5 )
  444.     ROM_LOAD_V20_ODD ( "raiden03.rom", 0x0c0000, 0x20000, 0xf6af09d0 )
  445.     ROM_LOAD_V20_EVEN( "raiden04.rom", 0x0c0000, 0x20000, 0x6bdfd416 )
  446.  
  447.     ROM_REGION( 0x100000, REGION_CPU2 ) /* v30 sub cpu */
  448.     ROM_LOAD_V20_ODD ( "raiden05.rom",   0x0c0000, 0x20000, 0xed03562e )
  449.     ROM_LOAD_V20_EVEN( "raiden06.rom",   0x0c0000, 0x20000, 0xa19d5b5d )
  450.  
  451.     ROM_REGION( 0x18000, REGION_CPU3 ) /* 64k code for sound Z80 */
  452.     ROM_LOAD( "raiden08.rom", 0x000000, 0x08000, 0x731adb43 )
  453.     ROM_CONTINUE(             0x010000, 0x08000 )
  454.  
  455.     ROM_REGION( 0x010000, REGION_GFX1 | REGIONFLAG_DISPOSE )
  456.     ROM_LOAD( "rai9.bin",     0x00000, 0x08000, 0x1922b25e ) /* chars */
  457.     ROM_LOAD( "rai10.bin",    0x08000, 0x08000, 0x5f90786a )
  458.  
  459.     ROM_REGION( 0x080000, REGION_GFX2 | REGIONFLAG_DISPOSE )
  460.     ROM_LOAD( "raiu0919.bin", 0x00000, 0x80000, 0xda151f0b ) /* tiles */
  461.  
  462.     ROM_REGION( 0x080000, REGION_GFX3 | REGIONFLAG_DISPOSE )
  463.     ROM_LOAD( "raiu0920.bin", 0x00000, 0x80000, 0xac1f57ac ) /* tiles */
  464.  
  465.     ROM_REGION( 0x090000, REGION_GFX4 | REGIONFLAG_DISPOSE )
  466.     ROM_LOAD( "raiu165.bin",  0x00000, 0x80000, 0x946d7bde ) /* sprites */
  467.  
  468.     ROM_REGION( 0x10000, REGION_SOUND1 )     /* ADPCM samples */
  469.     ROM_LOAD( "rai7.bin", 0x00000, 0x10000, 0x8f927822 )
  470. ROM_END
  471.  
  472. ROM_START( raidenk )
  473.     ROM_REGION( 0x100000, REGION_CPU1 ) /* v30 main cpu */
  474.     ROM_LOAD_V20_ODD ( "rai1.bin",     0x0a0000, 0x10000, 0xa4b12785 )
  475.     ROM_LOAD_V20_EVEN( "rai2.bin",     0x0a0000, 0x10000, 0x17640bd5 )
  476.     ROM_LOAD_V20_ODD ( "raiden03.rom", 0x0c0000, 0x20000, 0xf6af09d0 )
  477.     ROM_LOAD_V20_EVEN( "1i",           0x0c0000, 0x20000, 0xfddf24da )
  478.  
  479.     ROM_REGION( 0x100000, REGION_CPU2 ) /* v30 sub cpu */
  480.     ROM_LOAD_V20_ODD ( "raiden05.rom",   0x0c0000, 0x20000, 0xed03562e )
  481.     ROM_LOAD_V20_EVEN( "raiden06.rom",   0x0c0000, 0x20000, 0xa19d5b5d )
  482.  
  483.     ROM_REGION( 0x18000, REGION_CPU3 ) /* 64k code for sound Z80 */
  484.     ROM_LOAD( "8b",           0x000000, 0x08000, 0x99ee7505 )
  485.     ROM_CONTINUE(             0x010000, 0x08000 )
  486.  
  487.     ROM_REGION( 0x010000, REGION_GFX1 | REGIONFLAG_DISPOSE )
  488.     ROM_LOAD( "rai9.bin",     0x00000, 0x08000, 0x1922b25e ) /* chars */
  489.     ROM_LOAD( "rai10.bin",    0x08000, 0x08000, 0x5f90786a )
  490.  
  491.     ROM_REGION( 0x080000, REGION_GFX2 | REGIONFLAG_DISPOSE )
  492.     ROM_LOAD( "raiu0919.bin", 0x00000, 0x80000, 0xda151f0b ) /* tiles */
  493.  
  494.     ROM_REGION( 0x080000, REGION_GFX3 | REGIONFLAG_DISPOSE )
  495.     ROM_LOAD( "raiu0920.bin", 0x00000, 0x80000, 0xac1f57ac ) /* tiles */
  496.  
  497.     ROM_REGION( 0x090000, REGION_GFX4 | REGIONFLAG_DISPOSE )
  498.     ROM_LOAD( "raiu165.bin",  0x00000, 0x80000, 0x946d7bde ) /* sprites */
  499.  
  500.     ROM_REGION( 0x10000, REGION_SOUND1 )     /* ADPCM samples */
  501.     ROM_LOAD( "rai7.bin", 0x00000, 0x10000, 0x8f927822 )
  502. ROM_END
  503.  
  504. /***************************************************************************/
  505.  
  506. /* Spin the sub-cpu if it is waiting on the master cpu */
  507. static READ_HANDLER( sub_cpu_spin_r )
  508. {
  509.     int pc=cpu_get_pc();
  510.     int ret=raiden_shared_ram[0x8];
  511.  
  512.     if (offset==1) return raiden_shared_ram[0x9];
  513.  
  514.     if (pc==0xfcde6 && ret!=0x40)
  515.         cpu_spin();
  516.  
  517.     return ret;
  518. }
  519.  
  520. static READ_HANDLER( sub_cpu_spina_r )
  521. {
  522.     int pc=cpu_get_pc();
  523.     int ret=raiden_shared_ram[0x8];
  524.  
  525.     if (offset==1) return raiden_shared_ram[0x9];
  526.  
  527.     if (pc==0xfcde8 && ret!=0x40)
  528.         cpu_spin();
  529.  
  530.     return ret;
  531. }
  532.  
  533. static void init_raiden(void)
  534. {
  535.     install_mem_read_handler(1, 0x4008, 0x4009, sub_cpu_spin_r);
  536.     install_seibu_sound_speedup(2);
  537. }
  538.  
  539. static void memory_patcha(void)
  540. {
  541.     install_mem_read_handler(1, 0x4008, 0x4009, sub_cpu_spina_r);
  542.     install_seibu_sound_speedup(2);
  543. }
  544.  
  545. /* This is based on code by Niclas Karlsson Mate, who figured out the
  546. encryption method! The technique is a combination of a XOR table plus
  547. bit-swapping */
  548. static void common_decrypt(void)
  549. {
  550.     unsigned char *RAM = memory_region(REGION_CPU1);
  551.     int i,a;
  552.  
  553.     int xor_table[4][16]={
  554.       {0xF1,0xF9,0xF5,0xFD,0xF1,0xF1,0x3D,0x3D,   /* rom 3 */
  555.        0x73,0xFB,0x77,0xFF,0x73,0xF3,0x3F,0x3F},
  556.       {0xDF,0xFF,0xFF,0xFF,0xDB,0xFF,0xFB,0xFF,   /* rom 4 */
  557.        0xFF,0xFF,0xFF,0xFF,0xFB,0xFF,0xFB,0xFF},
  558.       {0x7F,0x7F,0xBB,0x77,0x77,0x77,0xBE,0xF6,   /* rom 5 */
  559.        0x7F,0x7F,0xBB,0x77,0x77,0x77,0xBE,0xF6},
  560.       {0xFF,0xFF,0xFD,0xFD,0xFD,0xFD,0xEF,0xEF,   /* rom 6 */
  561.        0xFF,0xFF,0xFD,0xFD,0xFD,0xFD,0xEF,0xEF}
  562.     };
  563.  
  564.     /* Rom 3 - main cpu even bytes */
  565.     for (i=0xc0000; i<0x100000; i+=2) {
  566.         a=RAM[i];
  567.         a^=xor_table[0][(i/2) & 0x0f];
  568.         a^=0xff;
  569.            a=(a & 0x31) | ((a<<1) & 0x04) | ((a>>5) & 0x02)
  570.         | ((a<<4) & 0x40) | ((a<<4) & 0x80) | ((a>>4) & 0x08);
  571.         RAM[i]=a;
  572.     }
  573.  
  574.     /* Rom 4 - main cpu odd bytes */
  575.     for (i=0xc0001; i<0x100000; i+=2) {
  576.         a=RAM[i];
  577.         a^=xor_table[1][(i/2) & 0x0f];
  578.         a^=0xff;
  579.            a=(a & 0xdb) | ((a>>3) & 0x04) | ((a<<3) & 0x20);
  580.         RAM[i]=a;
  581.     }
  582.  
  583.     RAM = memory_region(REGION_CPU2);
  584.  
  585.     /* Rom 5 - sub cpu even bytes */
  586.     for (i=0xc0000; i<0x100000; i+=2) {
  587.         a=RAM[i];
  588.         a^=xor_table[2][(i/2) & 0x0f];
  589.         a^=0xff;
  590.            a=(a & 0x32) | ((a>>1) & 0x04) | ((a>>4) & 0x08)
  591.         | ((a<<5) & 0x80) | ((a>>6) & 0x01) | ((a<<6) & 0x40);
  592.         RAM[i]=a;
  593.     }
  594.  
  595.     /* Rom 6 - sub cpu odd bytes */
  596.     for (i=0xc0001; i<0x100000; i+=2) {
  597.         a=RAM[i];
  598.         a^=xor_table[3][(i/2) & 0x0f];
  599.         a^=0xff;
  600.            a=(a & 0xed) | ((a>>3) & 0x02) | ((a<<3) & 0x10);
  601.         RAM[i]=a;
  602.     }
  603. }
  604.  
  605. static void init_raidenk(void)
  606. {
  607.     memory_patcha();
  608.     common_decrypt();
  609. }
  610.  
  611. static void init_raidena(void)
  612. {
  613.     memory_patcha();
  614.     common_decrypt();
  615.     seibu_sound_decrypt();
  616. }
  617.  
  618.  
  619. /***************************************************************************/
  620.  
  621. GAME( 1990, raiden,  0,      raiden,  raiden, raiden,  ROT270, "Seibu Kaihatsu", "Raiden" )
  622. GAMEX(1990, raidena, raiden, raidena, raiden, raidena, ROT270, "Seibu Kaihatsu", "Raiden (Alternate Hardware)", GAME_NO_SOUND )
  623. GAME( 1990, raidenk, raiden, raidena, raiden, raidenk, ROT270, "Seibu Kaihatsu (IBL Corporation license)", "Raiden (Korea)" )
  624.